home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / tcp.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-10-27  |  1.9 KB  |  105 lines

  1. /*
  2.                      shows how to use CreateIP() and CreateTCP()
  3.  
  4.                        THIS IS FOR EDUCATIONAL PORPOUSE ONLY!!!
  5.                               DON'T ASK WHAT IT IS FOR.
  6.                                DON'T EMAIL ME ABOUT IT.
  7.                  I DON'T ASSUME ANY RESPONSABILITY ABOUT USING OF IT.
  8. */
  9.  
  10. if ~show("L","rexxsupport.library") then
  11.     if ~addlib("rexxsupport.library",0,-30) then do
  12.         say "no rexxsupport.library"
  13.         exit
  14.     end
  15. if ~show("L","rxsocket.library") then
  16.     if ~addlib("rxsocket.library",0,-30) then do
  17.         say "no rxsocket.library"
  18.     exit
  19. end
  20. if ~show("L","rmh.library") then
  21.     if ~addlib("rmh.library",0,-30) then do
  22.         say "no rmh.library"
  23.         exit
  24.     end
  25.  
  26. prg=ProgramName("NOEXT")
  27.  
  28. if ~RMH_ReadArgs("FROM/A,TO/A,PORT/A/N") then do
  29.     call PrintFault(IoErr(),prg)
  30.     exit
  31. end
  32.  
  33. if parm.2.value<1 | parm.2.value>65535 then do
  34.     say "port '"parm.2.value"' not valid"
  35.     exit
  36. end
  37.  
  38. source = resolve(parm.0.value)
  39. if source==-1 then do
  40.     say "from host '"parm.0.value"' not found"
  41.     exit
  42. end
  43.  
  44. dest = resolve(parm.1.value)
  45. if dest==-1 then do
  46.     say "to host '"parm.1.value"' not found"
  47.     exit
  48. end
  49.  
  50. tcp.SPORT = 5000
  51. tcp.DPORT = parm.2.value
  52. tcp.SEQ      = 1
  53. tcp.ACK      = 0
  54. tcp.OFF      = 5
  55. tcp.FLAGS = 0
  56. tcp.WIN      = 21
  57. tcp.URP      = 1
  58. tcp.SRC      = source
  59. tcp.DST      = dest
  60.  
  61.  
  62. SIZEOFIP = 20
  63. ip.V   = 4
  64. ip.HL  = 5
  65. ip.TOS = 0
  66. ip.LEN = SIZEOFIP+length(tcpp)
  67. ip.ID  = 100
  68. ip.OFF = 0
  69. ip.TTL = 65
  70. ip.P   = 6
  71. ip.SUM = 0
  72. ip.SRC = source
  73. ip.DST = dest
  74.  
  75. sock = socket("INET","RAW","TCP")
  76. if sock<0 then do
  77.     say "no socket"
  78.     exit
  79. end
  80.  
  81. if setsockopt(sock,"IP","HDRINCL",1)<0 then do
  82.     say "no IP HDRINCL"
  83.     exit
  84. end
  85.  
  86. remote.addrfamily = "INET"
  87. remote.addraddr   = dest
  88.  
  89. do i=0 to 255
  90.     packet = createPacket(i);
  91.     res = sendto(sock,packet,0,"REMOTE")
  92.     if res==-1 then do
  93.         say res Errno()
  94.         exit
  95.     end
  96. end
  97. exit
  98.  
  99. createPacket: PROCEDURE EXPOSE ip. tcp.
  100. parse arg f
  101.     tcp.FLAGS = f
  102.     ipp = CreateIP("IP")
  103.     tcpp = CreateTCP("TCP")
  104.     return ipp || tcpp
  105.